"use strict";

var timeout;
app.controller("QueryPaymentOperationController", ["$scope", "$modal", "$timeout", "RESTService",
                                function($scope,   $modal,   $timeout,   RESTService) {
    
    $scope.servReqs = [];

    $scope.item = {
    	startDate: moment(new Date()).format('YYYY-MM-01'),
    	finishDate: moment(new Date()).format('YYYY-MM-DD')
    }
    $scope.summaryOfAmount_Operation = 0;
    $scope.summaryOfAmount_Regional = 0;
    $scope.summaryOfAmount_Expert = 0;
    $scope.summaryOfAmount_Operator = 0;
    $scope.summaryOfAmount_Platform = 0;
    
    var loadListData = function() {
    	var startDate = moment($scope.item.startDate).format('YYYY-MM-DD');
    	var finishDate = moment($scope.item.finishDate).format('YYYY-MM-DD');
    	
    	RESTService.getResponse("/rest/servreq/getHospFees?paid_Operation=true&pageNo=1&pageSize=1000" +
    		"&startDate=" + startDate + "&finishDate=" + finishDate).then(function(response) {
	    	$scope.hospFees = response;

		    $scope.summaryOfAmount_Operation = 0;
		    $scope.summaryOfAmount_Regional = 0;
		    $scope.summaryOfAmount_Expert = 0;
		    $scope.summaryOfAmount_Operator = 0;
		    $scope.summaryOfAmount_Platform = 0;

            angular.forEach(response, function(item) {
                $scope.summaryOfAmount_Operation += item.amount_Operation;
                $scope.summaryOfAmount_Regional += item.amount_Regional;
                $scope.summaryOfAmount_Expert += item.amount_Expert;
                $scope.summaryOfAmount_Operator += item.amount_Operator;
                $scope.summaryOfAmount_Platform += item.amount_Platform;
            });
	    	
	    });
    }
    $scope.init = function() {
    	loadListData();
    }
    $scope.query = function() {
    	loadListData();
    }
}]);
